<template>
    <div>

        <h1>病房信息显示</h1>
        <a href="/addbf">添加病房</a>
        <br>
          <a href="/show">科室信息</a>
          <br>
          <a href="/showys">医生信息</a> 
        <br>
        病房名称:
        <input type="text" pattern="病房名称" v-model="page.housenum">
        科室:
        <select v-model="page.ksid">
            <option value="0">请选择科室</option>
            <option v-for="e in KSxlk" :value="e.id">{{ e.departName }}</option>
        </select> 
        <input type="button" value="查询" @click="chax">
        <table class="table">
            <thead>
                <tr>
                    <td>病房编号</td>
                    <td>病房号</td>
                    <td>床位总数量</td>
                    <td>病房状态</td>
                    <td>空闲床数量</td>
                    <td>床铺状态</td> 
                    <td>科室</td> 
                    <td>日期</td> 
                    <td>修改状态</td>
                </tr>
            </thead>
            <tbody>
                 <tr v-for="e in data">
                    <td>{{ e.id }}</td>
                    <td>{{ e.houseName }}</td>
                    <td>{{ e.houseSUM }}</td>
                    <td>{{ e.isState?'维修':'启用' }}</td> 
                    <td>{{ e.houseCount }}</td> 
                    <td>{{ e.houseState?'未满':'已住满' }}</td> 
                    <td>{{ e.departName }}</td> 
                    <td>{{ moment(e.houseDate).format("YYYY-MM-DD") }}</td>  
                    <td>
                        <input type="button" :value="e.isState?'启用':'维修'" @click="updatestate(e.id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import moment from 'moment';
import { useRouter } from 'vue-router'
import {useUserStore} from '../../stores/user'

const user = useUserStore();
const router=useRouter();
onMounted(()=>{
     if(user.userinfo.name=="")
{
     alert("你还没登录,请先登录")
     router.push({path:"/login"})
}
XLKS();
    show();
})

const chax=()=>{ 
    show();
}

//修改状态
const updatestate=(val:any)=>{
    if(!confirm("确认修改状态吗"))
{
    return;
}
    axios.get("/api/Housenum/UpdateState",{params:{id:val}}).then(res=>{
        if(res.data>0)
    {
        alert("状态修改成功");
        show();
    }
    else{
        alert("状态修改失败");
        return;
    }
    })
}

//科室下拉框
const KSxlk=ref([{
    "id": 1,
    "departName": "内科",
}])
const XLKS=()=>{
    axios.get("/api/Depart/Showxlk").then(res=>{
        KSxlk.value=res.data
    })
}

const data =ref([{
    "id": 1,
    "houseName": "病房号1",
    "departid": 1,
    "houseSUM": 5,
    "isState": false,
    "houseState": true,
    "houseCount": 3,
    "houseDate": "2025-05-13T20:22:56.6053872",
    "departName": "内科"
  }])
 const page =ref({
    housenum:"",
    ksid:0
 })
 

const show =()=>{
    axios.get("/api/Housenum/ShowBF",{params:page.value}).then(res=>{
        data.value=res.data
    })
}

</script>

<style scoped>

</style>    